/**      
 * @file		strncpy_more.cpp
 * @description	More examples of strncpy	
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
#include <cstring>
using namespace std;

/**
 * @return zero if the application executes successfully
 */
int main() {
	char cString1[] = "Please email my message to the class!";
	char cString2[50];

	cout << "This application demonstrates how to copy cstrings\n";
	cout << "Remember we can't use the assignment operator, = to assign";
	cout << " cstrings values unless we use it when we declare the cstring\n";
	cout << "We'll use strncpy(destination, source, numOfChars) to copy cString1 to cString2\n";
	cout << "strncpy(cString2, cString1, 37);\n";

	strncpy(cString2, cString1, 37);
	cString2[49] = '\0';

	cout << "cString1 = " << cString1 << endl;
	cout << "cString2 = '" << cString2 << "'\n";

	//If third argument is less than or equal to the length of source, 
	//a null character is not appended automatically to the copied string.
	//If count is greater than the length of source, the destination 
	//string is padded with null characters up to length count.
	//strncpy does not check for sufficient space in destination; it is therefore 
	//a potential cause of buffer overruns. Keep in mind that count limits 
	//the number of characters copied; it is not a limit on the size of destination

	return 0;
}
